from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-27 14:08:12.423036
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 27, Jan, 2021
Time: 14:08:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5933
Nobs: 184.000 HQIC: -46.5284
Log likelihood: 2079.49 FPE: 3.28527e-21
AIC: -47.1658 Det(Omega_mle): 2.04040e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445407 0.141998 3.137 0.002
L1.Burgenland 0.127899 0.074549 1.716 0.086
L1.Kärnten -0.233105 0.061013 -3.821 0.000
L1.Niederösterreich 0.128963 0.170200 0.758 0.449
L1.Oberösterreich 0.212450 0.149454 1.422 0.155
L1.Salzburg 0.190753 0.078947 2.416 0.016
L1.Steiermark 0.100308 0.106511 0.942 0.346
L1.Tirol 0.162284 0.071038 2.284 0.022
L1.Vorarlberg -0.005570 0.066587 -0.084 0.933
L1.Wien -0.115181 0.142938 -0.806 0.420
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.501940 0.180545 2.780 0.005
L1.Burgenland 0.020402 0.094786 0.215 0.830
L1.Kärnten 0.370561 0.077575 4.777 0.000
L1.Niederösterreich 0.108832 0.216402 0.503 0.615
L1.Oberösterreich -0.169105 0.190024 -0.890 0.374
L1.Salzburg 0.188562 0.100378 1.879 0.060
L1.Steiermark 0.250105 0.135424 1.847 0.065
L1.Tirol 0.137349 0.090322 1.521 0.128
L1.Vorarlberg 0.177117 0.084663 2.092 0.036
L1.Wien -0.573356 0.181740 -3.155 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290435 0.064167 4.526 0.000
L1.Burgenland 0.114407 0.033688 3.396 0.001
L1.Kärnten -0.024796 0.027571 -0.899 0.368
L1.Niederösterreich 0.066648 0.076911 0.867 0.386
L1.Oberösterreich 0.285336 0.067536 4.225 0.000
L1.Salzburg 0.006693 0.035675 0.188 0.851
L1.Steiermark -0.023229 0.048131 -0.483 0.629
L1.Tirol 0.093035 0.032101 2.898 0.004
L1.Vorarlberg 0.116992 0.030090 3.888 0.000
L1.Wien 0.079212 0.064592 1.226 0.220
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213065 0.073582 2.896 0.004
L1.Burgenland -0.009683 0.038631 -0.251 0.802
L1.Kärnten 0.022383 0.031616 0.708 0.479
L1.Niederösterreich 0.033831 0.088196 0.384 0.701
L1.Oberösterreich 0.390672 0.077445 5.045 0.000
L1.Salzburg 0.097523 0.040909 2.384 0.017
L1.Steiermark 0.180016 0.055193 3.262 0.001
L1.Tirol 0.041880 0.036811 1.138 0.255
L1.Vorarlberg 0.094137 0.034505 2.728 0.006
L1.Wien -0.066488 0.074069 -0.898 0.369
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.529910 0.146743 3.611 0.000
L1.Burgenland 0.078409 0.077040 1.018 0.309
L1.Kärnten 0.005397 0.063052 0.086 0.932
L1.Niederösterreich -0.015337 0.175887 -0.087 0.931
L1.Oberösterreich 0.147155 0.154447 0.953 0.341
L1.Salzburg 0.052861 0.081585 0.648 0.517
L1.Steiermark 0.115952 0.110070 1.053 0.292
L1.Tirol 0.214615 0.073412 2.923 0.003
L1.Vorarlberg 0.014744 0.068812 0.214 0.830
L1.Wien -0.131058 0.147714 -0.887 0.375
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155937 0.104009 1.499 0.134
L1.Burgenland -0.018273 0.054605 -0.335 0.738
L1.Kärnten -0.015361 0.044690 -0.344 0.731
L1.Niederösterreich 0.129264 0.124666 1.037 0.300
L1.Oberösterreich 0.395610 0.109470 3.614 0.000
L1.Salzburg -0.024615 0.057826 -0.426 0.670
L1.Steiermark -0.034694 0.078016 -0.445 0.657
L1.Tirol 0.189983 0.052033 3.651 0.000
L1.Vorarlberg 0.046264 0.048773 0.949 0.343
L1.Wien 0.183170 0.104697 1.750 0.080
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.216795 0.132756 1.633 0.102
L1.Burgenland 0.085901 0.069697 1.232 0.218
L1.Kärnten -0.045948 0.057042 -0.806 0.421
L1.Niederösterreich -0.006941 0.159122 -0.044 0.965
L1.Oberösterreich -0.107934 0.139726 -0.772 0.440
L1.Salzburg 0.028158 0.073809 0.381 0.703
L1.Steiermark 0.386100 0.099578 3.877 0.000
L1.Tirol 0.493746 0.066415 7.434 0.000
L1.Vorarlberg 0.174731 0.062253 2.807 0.005
L1.Wien -0.223244 0.133634 -1.671 0.095
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120049 0.157629 0.762 0.446
L1.Burgenland 0.017268 0.082755 0.209 0.835
L1.Kärnten -0.105580 0.067729 -1.559 0.119
L1.Niederösterreich 0.245229 0.188935 1.298 0.194
L1.Oberösterreich 0.020636 0.165905 0.124 0.901
L1.Salzburg 0.220642 0.087637 2.518 0.012
L1.Steiermark 0.120773 0.118235 1.021 0.307
L1.Tirol 0.084974 0.078858 1.078 0.281
L1.Vorarlberg 0.026076 0.073917 0.353 0.724
L1.Wien 0.260559 0.158672 1.642 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.581632 0.084788 6.860 0.000
L1.Burgenland -0.018846 0.044514 -0.423 0.672
L1.Kärnten -0.002444 0.036431 -0.067 0.947
L1.Niederösterreich -0.037879 0.101628 -0.373 0.709
L1.Oberösterreich 0.281797 0.089240 3.158 0.002
L1.Salzburg 0.016575 0.047140 0.352 0.725
L1.Steiermark 0.013957 0.063599 0.219 0.826
L1.Tirol 0.079103 0.042418 1.865 0.062
L1.Vorarlberg 0.150374 0.039760 3.782 0.000
L1.Wien -0.060407 0.085350 -0.708 0.479
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149831 0.002160 0.210566 0.252589 0.067433 0.061785 -0.066344 0.166285
Kärnten 0.149831 1.000000 0.021590 0.197856 0.162661 -0.113672 0.172261 0.026008 0.315635
Niederösterreich 0.002160 0.021590 1.000000 0.301160 0.081695 0.215810 0.126409 0.060252 0.360992
Oberösterreich 0.210566 0.197856 0.301160 1.000000 0.301793 0.302575 0.107648 0.082622 0.127603
Salzburg 0.252589 0.162661 0.081695 0.301793 1.000000 0.156177 0.053236 0.077226 -0.017960
Steiermark 0.067433 -0.113672 0.215810 0.302575 0.156177 1.000000 0.104600 0.091235 -0.099391
Tirol 0.061785 0.172261 0.126409 0.107648 0.053236 0.104600 1.000000 0.161341 0.142667
Vorarlberg -0.066344 0.026008 0.060252 0.082622 0.077226 0.091235 0.161341 1.000000 0.077785
Wien 0.166285 0.315635 0.360992 0.127603 -0.017960 -0.099391 0.142667 0.077785 1.000000